[id].vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <!-- 页面头部 -->
  3. <HomePageHead></HomePageHead>
  4. <!-- Banner1 -->
  5. <HomeBanner1></HomeBanner1>
  6. <!-- 面包屑导航 -->
  7. <div class="breadcrumb">
  8. <div class="inner">
  9. <span class="location">当前位置:</span>
  10. <el-breadcrumb :separator-icon="ArrowRight">
  11. <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
  12. <el-breadcrumb-item :to="{ path: `/primaryNavigation/${listid}` }" v-show="name">{{ name
  13. }}</el-breadcrumb-item>
  14. <el-breadcrumb-item>{{ routeNewsTtitle }}</el-breadcrumb-item>
  15. </el-breadcrumb>
  16. </div>
  17. </div>
  18. <!-- 资讯列表 -->
  19. <div class="newsDetail">
  20. <div class="inner">
  21. <div class="innerLeft">
  22. <div class="LeftTop">
  23. <h1>{{ newsDetail.title }}</h1>
  24. <p>
  25. 来源: <span>{{ newsDetail.copyfrom }}</span>
  26. 作者: <span>{{ newsDetail.author }}</span>
  27. <span>{{ newsDetail.updated_at }}</span>
  28. <!-- 浏览量: <span>{{ newsDetail.hits }}</span> -->
  29. </p>
  30. <img :src="newsDetail.imgurl" alt="">
  31. </div>
  32. <div class="leftBottom" v-html="newsDetail.content">
  33. </div>
  34. </div>
  35. <div class="innerRight">
  36. <!-- 热点资讯1 -->
  37. <div class="hotList1">
  38. <DetailHotNews></DetailHotNews>
  39. </div>
  40. <!-- 热点资讯2 -->
  41. <div class="hotList2">
  42. <DetailHotNews2></DetailHotNews2>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <!-- 页面底部 -->
  48. <HomeFoot></HomeFoot>
  49. </template>
  50. <script setup>
  51. import { onMounted } from 'vue'
  52. import { ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'
  53. import { ArrowRight } from '@element-plus/icons-vue'
  54. const nuxtApp = useNuxtApp();
  55. const axios = nuxtApp.$axios;
  56. //获得跳转过来的id
  57. const route = useRoute();
  58. const articleId = route.params.id; //获得该页面的id
  59. const listid = route.query.listId; //获得该页面的id
  60. const name = route.query.listName; //获得该页面的id
  61. // 定义响应式数据
  62. const seoData = ref({
  63. title: '三农资讯网',
  64. description: '默认描述',
  65. keywords: '默认关键词',
  66. image: 'https://example.com/default-image.jpg'
  67. });
  68. // 在 onMounted 钩子中获取数据
  69. onMounted(async () => {
  70. try {
  71. const response = await axios.get(`/web/getWebsiteCategoryHead?catid=${articleId}`);
  72. const data = response.data.website_head; // 假设接口返回的数据在 data 字段中
  73. console.log(seoData.value.title)
  74. // 更新 seoData
  75. seoData.value = {
  76. title: data.seo_title,
  77. description: data.seo_description,
  78. keywords: data.seo_keywords,
  79. image: data.seo_image
  80. };
  81. console.log(seoData.value.title)
  82. } catch (error) {
  83. console.error('获取 SEO 数据失败:', error);
  84. // 设置默认值
  85. seoData.value = {
  86. title: '三农资讯网',
  87. description: '默认描述',
  88. keywords: '默认关键词',
  89. image: 'https://example.com/default-image.jpg'
  90. };
  91. }
  92. });
  93. // 监听 seoData 的变化,动态设置 SEO 字段
  94. watch(seoData, (newVal) => {
  95. if (newVal.title) { // 确保 title 有值
  96. useSeoMeta({
  97. title: newVal.title, // 使用动态值
  98. description: newVal.description,
  99. ogTitle: newVal.title,
  100. ogDescription: newVal.description,
  101. ogImage: newVal.image,
  102. twitterTitle: newVal.title,
  103. twitterDescription: newVal.description,
  104. twitterImage: newVal.image,
  105. keywords: newVal.keywords
  106. });
  107. }
  108. }, { immediate: true });
  109. const newsDetail = ref({})
  110. console.log(articleId)
  111. const routeNewsTtitle = ref("");
  112. //获取详情
  113. const getNewsInfo = async () => {
  114. const response = await axios.get(`/web/selectWebsiteArticleInfo?articleid=${articleId}`);
  115. newsDetail.value = response.data;
  116. console.log(333555666)
  117. console.log(newsDetail.value.title)
  118. if (newsDetail.value.title.length >= 30) {
  119. routeNewsTtitle.value = newsDetail.value.title.substr(0, 30) + "...";
  120. }else{
  121. routeNewsTtitle.value = newsDetail.value.title
  122. }
  123. }
  124. onMounted(() => {
  125. getNewsInfo()
  126. })
  127. </script>
  128. <style lang="less" scoped>
  129. //导航条
  130. .breadcrumb {
  131. width: 100%;
  132. height: 22px;
  133. margin-bottom: 30px;
  134. font-family: Microsoft YaHei, Microsoft YaHei;
  135. font-weight: 400;
  136. font-size: 20px;
  137. color: #666666;
  138. line-height: 23px;
  139. text-align: left;
  140. font-style: normal;
  141. text-transform: none;
  142. .el-breadcrumb::v-deep {
  143. display: inline-block;
  144. vertical-align: -4px;
  145. }
  146. /deep/.el-breadcrumb__inner a,
  147. /deep/.el-breadcrumb__inner.is-link {
  148. color: #666666;
  149. font-weight: 400;
  150. text-decoration: none;
  151. transition: var(--el-transition-color);
  152. }
  153. span {
  154. font-family: Microsoft YaHei, Microsoft YaHei;
  155. font-weight: 400;
  156. font-size: 20px;
  157. color: #666666;
  158. line-height: 23px;
  159. text-align: left;
  160. font-style: normal;
  161. text-transform: none;
  162. }
  163. span:hover {
  164. color: #666666;
  165. }
  166. .location {
  167. margin-right: 20px;
  168. width: 100px;
  169. height: 22px;
  170. font-family: Microsoft YaHei, Microsoft YaHei;
  171. font-weight: 400;
  172. font-size: 20px;
  173. color: #666666;
  174. line-height: 23px;
  175. text-align: left;
  176. font-style: normal;
  177. text-transform: none;
  178. }
  179. }
  180. // 资讯列表
  181. .newsDetail {
  182. width: 100%;
  183. //height: 1400px;
  184. margin-bottom: 70px;
  185. .inner {
  186. width: 1200px;
  187. //height: 1400px;
  188. overflow: hidden;
  189. font-size: 16px;
  190. .innerLeft {
  191. // height: 1400px;
  192. border-top: 1px solid #139602;
  193. .LeftTop {
  194. height: 522px;
  195. margin-top: 50px;
  196. >h1 {
  197. line-height: 40px;
  198. margin-bottom: 30px;
  199. font-family: Microsoft YaHei, Microsoft YaHei;
  200. font-weight: bold;
  201. font-size: 30px;
  202. color: #333333;
  203. }
  204. >p {
  205. height: 18px;
  206. line-height: 18px;
  207. font-family: Microsoft YaHei, Microsoft YaHei;
  208. font-weight: 400;
  209. font-size: 14px;
  210. color: #999999;
  211. span {
  212. margin-right: 40px;
  213. }
  214. }
  215. >img {
  216. width: 680px;
  217. height: 382px;
  218. padding: 50px 0px 60px 55px;
  219. }
  220. }
  221. .leftBottom {
  222. width: 790px;
  223. // height: 754px;
  224. margin-top: 76px;
  225. font-size: 20px;
  226. line-height: 38px;
  227. // img{
  228. // width: 790px;
  229. // height: 382px;
  230. // }
  231. >h3,
  232. >p {
  233. text-indent: 2em;
  234. width: 790px;
  235. font-family: Microsoft YaHei, Microsoft YaHei;
  236. font-size: 20px;
  237. color: #333333;
  238. line-height: 38px;
  239. padding-bottom: 30px;
  240. }
  241. >h3 {
  242. font-weight: 600px;
  243. }
  244. >p {
  245. font-weight: 400;
  246. }
  247. }
  248. }
  249. .innerRight {
  250. width: 381px;
  251. // height: 605px;
  252. overflow: hidden;
  253. border-top: 1px solid #139602;
  254. .hotList1 {
  255. margin-bottom: 50px;
  256. }
  257. }
  258. }
  259. }
  260. </style>